package com.qfedu.edu.seckill.orderservice.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author xiaobobo
 * @title: OrderNumberUtils
 * @projectName cd-java-2404-seckill-parent
 * @description: 订单号的工具类
 * @date 2025/2/6  10:30
 */
public class OrderNumberUtils {

    private static AtomicLong atomicLong = new AtomicLong(0);

    /**
     * 生成订单号(这个方法也需要加锁(分布式锁))
     *
     * @return
     */
    public static String getOrderNumber() {
        /**
         * 策略：
         *    1、年月日时分秒
         *    2、数的自增
         *    3、UUID的hashCode值
         */
        String first = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        long second = atomicLong.incrementAndGet();
        int third = UUID.randomUUID().toString().replace("-", "").hashCode();
        return first + second + third;
    }


}
